package com.example.shimmer;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;


import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

public class GetDataTask extends AsyncTask<String, Integer, List<String>>{

	private Context mContext;

	public GetDataTask(Context context) {
		super();
		mContext = context;
	}
	@Override
	protected List<String> doInBackground(String... params) {
		try {
			return parseNewsJSON();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public List<String> parseNewsJSON() throws IOException {
		List<String> res = new ArrayList<String>();
		String menuJson = "";
		String menuUrl = "http://110.75.216.110:443/openapi/param2/1/aliexpress.open/api.findAeProductById/5764485?productId=1844850934&access_token=d48a3eb3-583a-4ab6-877f-ac82437c906c&_aop_signature=3765DA7B239E32461532DA43E8A3E60345571123";
		menuJson = HttpUtil.get(menuUrl);
		Log.d("MainActiivty", "json:" + menuJson);

		try {
			if(menuJson!=null){
				JSONObject mjObject = new JSONObject(menuJson);
				JSONArray arctypesJson = mjObject.getJSONArray("arctypeList");
				for(int i=0;i<arctypesJson.length();i++){
					JSONObject menuObject = arctypesJson.getJSONObject(i);
//					String menu = new res();
//					menu.setTypeId(menuObject.isNull("id")?1:menuObject.getInt("id"));
//					menu.setText(menuObject.isNull("typeName")?"":menuObject.getString("typeName"));
//					
//					menus.add(menu);
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return res;
	}
	

}
